package com.orange.lockscreen.layers.background;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.graphics.Bitmap;

import com.orange.lockscreen.SlatHashMap;
import com.orange.lockscreen.layers.SlatPanel;

/**
 * 
 * BackgoundSlatPanel: contains backgroundslat.
 * 
 * Deprecated
 * 
 */
public class BackgroundSlatPanel extends SlatPanel {

	public static final String		TAG					= "BackgroundSlatPanel";
	private List<BackgroundSlat>	mBackgroundSlats	= null;

	public BackgroundSlatPanel(Context context) {
		super(context);
	}

	@Override
	protected void init() {
		BackgroundSlat bgSlat = null;
		int slatCount = SlatHashMap.getCount();
		mBackgroundSlats = new ArrayList<BackgroundSlat>(slatCount);
		for (int i = 0; i < slatCount; i++) {
			bgSlat = new BackgroundSlat(getContext());
			mBackgroundSlats.add(bgSlat);
			addView(bgSlat);
		}
	}

	public void showBackgroundSlat(int rowIndex) {
		if (mBackgroundSlats == null) {
			return;
		}
		int slatCount = mBackgroundSlats.size();
		if (rowIndex < slatCount) {
			BackgroundSlat slat = mBackgroundSlats.get(rowIndex);
			if (!slat.isShown()) {
				slat.setVisibility(VISIBLE);
			}
		}
	}

	public void unshowBackgroundSlat(int rowIndex) {
		if (mBackgroundSlats == null) {
			return;
		}
		int slatCount = mBackgroundSlats.size();
		if (rowIndex < slatCount) {
			BackgroundSlat slat = mBackgroundSlats.get(rowIndex);
			if (slat.isShown()) {
				slat.setVisibility(INVISIBLE);
			}
		}
	}

	public Bitmap getSlatDrawCache(int index) {
		return mBackgroundSlats.get(index).getSlatDrawCache();
	}

	public void setSlatDraws(Bitmap[] bitmaps) {
		int count = bitmaps.length;
		Bitmap bitmap = null;
		synchronized (mBackgroundSlats) {
			for (int i = 0; i < count; i++) {
				bitmap = bitmaps[i];
				if (null != bitmap) {
					mBackgroundSlats.get(i).setWallPaperPiece(bitmap);
				}
			}
		}
	}

	public void release() {
		if (null != mBackgroundSlats) {
			BackgroundSlat slat = null;
			int slatCount = SlatHashMap.getCount();
			for (int i = 0; i < slatCount; i++) {
				slat = mBackgroundSlats.get(i);
				slat.release();
			}
			mBackgroundSlats.clear();
			mBackgroundSlats = null;
		}
	}
}
